package com.wswy.wzcx.ui.car.choose

import android.support.v7.widget.RecyclerView
import android.text.TextUtils
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import com.che.libcommon.ui.adapter.SampleRecyclerViewAdapter
import com.timehop.stickyheadersrecyclerview.StickyRecyclerHeadersAdapter
import com.wswy.wzcx.R
import com.wswy.wzcx.model.car.CarTypeInfo
import kotlinx.android.synthetic.main.layout_item_car_brand.view.*

class BrandsAdapter(val showIcon:Boolean=true) : SampleRecyclerViewAdapter<CarTypeInfo,BrandsAdapter.ViewHolder>(), StickyRecyclerHeadersAdapter<BrandsAdapter.HeaderViewHolder> {


    override fun getHeaderId(position: Int): Long {
        return getItemData(position)?.headerId?:0
    }

    override fun onCreateHeaderViewHolder(parent: ViewGroup?): HeaderViewHolder {
        return HeaderViewHolder(LayoutInflater.from(parent?.context).inflate(R.layout.layout_item_car_header,parent,false))
    }

    override fun onBindHeaderViewHolder(holder: HeaderViewHolder?, position: Int) {


        holder?.tvTitle?.text = getItemData(position)?.headerTitle
    }


    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        return ViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.layout_item_car_brand,parent,false))
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int, data: CarTypeInfo?) {
        holder.itemView.tv_name.text = data?.name
        if (showIcon){
            holder.itemView.img_brand_icon.visibility = View.VISIBLE
            holder.itemView.img_brand_icon.setImageURI(data?.logo)
        }else{
            holder.itemView.img_brand_icon.visibility = View.GONE
        }

    }


    class ViewHolder (itemView:View): RecyclerView.ViewHolder(itemView)

    class HeaderViewHolder (itemView:View): RecyclerView.ViewHolder(itemView){
        var tvTitle:TextView = itemView as TextView

    }
}